-
Notifications
You must be signed in to change notification settings - Fork 128
Two handy extensions to work with HTTPClientResponse body #736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally these look really good! Can you add a couple of tests for them as well?
It's been a while but I updated it :) |
Sources/AsyncHTTPClient/AsyncAwait/HTTPClientResponse+data.swift
Outdated
Show resolved
Hide resolved
/// - Parameter maxBytes: The maximum number of bytes this method is allowed to accumulate. | ||
/// - Returns: Bytes collected over time | ||
public func bytes(upTo maxBytes: Int) async throws -> ByteBuffer { | ||
let expectedBytes = self.headers.first(name: "content-length").flatMap(Int.init) ?? maxBytes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should always use maxBytes
and never the value from content-length
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Co-authored-by: Cory Benfield <[email protected]>
Co-authored-by: Cory Benfield <[email protected]>
Two extensions for
HTTPClientResponse
to avoid boilerplate code.Reading a response data currently:
With the extension:
Additionally an extension for
bytes
. Currently:With the extension: